<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Penerbit extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('Penerbit_model');
		if(!$this->session->userdata('rule')== '1' && !$this->session->userdata('username') ){
			redirect('kategori');
		}
	}

	function index() 
	{		$offset = $this->uri->segment(3);
			$config['base_url'] = $this->config->site_url().'/penerbit/index';
			$config['total_rows'] = $this->db->count_all('tb_penerbit');
			$config['per_page'] = 10;
			$config['uri_segment'] = '3';		
			$data['status'] = 'Data Penerbit';	
		$data['urutan'] = $this->uri->segment(3);	
			$this->load->library('pagination');
			$data['title'] = 'Data Penerbit';
			$data['query'] = $this->Penerbit_model->getPenerbit('list',FALSE,$config['per_page'],$offset);
			$data['main_view'] = 'penerbit/penerbit';
			$this->pagination->initialize($config);
			$this->load->view('index',$data);
		
	}

	function add(){
		$this->form_validation->set_rules('penerbit','nama matkul','required');
			if ($this->form_validation->run() == FALSE){
		$data['title'] = 'Tambah Penerbit';
		$data['main_view'] = 'penerbit/add';
		$data['status'] = 'Add Data Penerbit';
		$this->load->view('index',$data);
			}
			else {
				$data = array('nama_penerbit'=> $this->input->post('penerbit'));
				
				$this->Penerbit_model->addPenerbit($data);
				redirect('penerbit');
			}
	}
	
	function edit(){
		$this->form_validation->set_rules('penerbit','penerbit','required');
				if ($this->form_validation->run() == FALSE) {
					$id_penerbit = $this->uri->segment(3);
				$data['title'] = 'Edit Penerbit';
				$data['row'] = $this->Penerbit_model->getPenerbit('by_id',$id_penerbit,FALSE,FALSE,FALSE);
				$data['main_view'] = 'penerbit/edit';
				$data['status'] = 'Edit Data Penerbit';
				$this->load->view('index',$data);
			}
			else {
			$id = $this->uri->segment(3);
				$data = array('nama_penerbit'=> $this->input->post('penerbit'));
				$this->Penerbit_model->editPenerbit($id,$data);
				redirect('penerbit');
			}
	}
	function delete(){
		$id = $this->uri->segment(3);
		$this->Penerbit_model->deletePenerbit($id);
		redirect('penerbit');
	
	}
	
}

?>